package com.example.imagetest.util;

import android.util.Log;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 日志记录的拦截器
 */
public class LoggingInterceptor implements Interceptor {
    private static final String TAG = "HTTP_LOG";

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

        // 使用Log打印请求头信息
        Log.d(TAG, "Request Headers: ");
        for (String name : request.headers().names()) {
            Log.d(TAG, name + ": " + request.header(name));
        }

        // 打印请求URL
        Log.d(TAG, "Request URL: " + request.url());

        Response response = chain.proceed(request);
        return response;
    }
}
